/*
 * Artificial Intelligence for Humans
 * Volume 1: Fundamental Algorithms
 * C/C++ Version
 * http://www.aifh.org
 * http://www.jeffheaton.com
 *
 * Code repository:
 * https://github.com/jeffheaton/aifh

 * Copyright 2013 by Jeff Heaton
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * For more information on Heaton Research copyrights, licenses
 * and trademarks visit:
 * http://www.heatonresearch.com/copyright
 */
#include "aifh-vol1-examples.h"

/*
This example shows how to normalize the iris data set.  Equilateral encoding is used for the species, and range
is used for the measurements.


Actual input count: 4
Actual output count: 2
"sepal_length","sepal_width","petal_length-0","petal_length-1"
0.222222,0.625000,0.067797,0.041667,0.066987,0.250000
0.166667,0.416667,0.067797,0.041667,0.066987,0.250000
0.111111,0.500000,0.050847,0.041667,0.066987,0.250000
0.083333,0.458333,0.084746,0.041667,0.066987,0.250000
0.194444,0.666667,0.067797,0.041667,0.066987,0.250000
0.305556,0.791667,0.118644,0.125000,0.066987,0.250000
0.083333,0.583333,0.067797,0.083333,0.066987,0.250000
0.194444,0.583333,0.084746,0.041667,0.066987,0.250000
0.027778,0.375000,0.067797,0.041667,0.066987,0.250000
0.166667,0.458333,0.084746,0.000000,0.066987,0.250000
0.305556,0.708333,0.084746,0.041667,0.066987,0.250000
0.138889,0.583333,0.101695,0.041667,0.066987,0.250000
0.138889,0.416667,0.067797,0.000000,0.066987,0.250000
0.000000,0.416667,0.016949,0.000000,0.066987,0.250000
0.416667,0.833333,0.033898,0.041667,0.066987,0.250000
0.388889,1.000000,0.084746,0.125000,0.066987,0.250000
0.305556,0.791667,0.050847,0.125000,0.066987,0.250000
0.222222,0.625000,0.067797,0.083333,0.066987,0.250000
0.388889,0.750000,0.118644,0.083333,0.066987,0.250000
0.222222,0.750000,0.084746,0.083333,0.066987,0.250000
0.305556,0.583333,0.118644,0.041667,0.066987,0.250000
0.222222,0.708333,0.084746,0.125000,0.066987,0.250000
0.083333,0.666667,0.000000,0.041667,0.066987,0.250000
0.222222,0.541667,0.118644,0.166667,0.066987,0.250000
0.138889,0.583333,0.152542,0.041667,0.066987,0.250000
0.194444,0.416667,0.101695,0.041667,0.066987,0.250000
0.194444,0.583333,0.101695,0.125000,0.066987,0.250000
0.250000,0.625000,0.084746,0.041667,0.066987,0.250000
0.250000,0.583333,0.067797,0.041667,0.066987,0.250000
0.111111,0.500000,0.101695,0.041667,0.066987,0.250000
0.138889,0.458333,0.101695,0.041667,0.066987,0.250000
0.305556,0.583333,0.084746,0.125000,0.066987,0.250000
0.250000,0.875000,0.084746,0.000000,0.066987,0.250000
0.333333,0.916667,0.067797,0.041667,0.066987,0.250000
0.166667,0.458333,0.084746,0.000000,0.066987,0.250000
0.194444,0.500000,0.033898,0.041667,0.066987,0.250000
0.333333,0.625000,0.050847,0.041667,0.066987,0.250000
0.166667,0.458333,0.084746,0.000000,0.066987,0.250000
0.027778,0.416667,0.050847,0.041667,0.066987,0.250000
0.222222,0.583333,0.084746,0.041667,0.066987,0.250000
0.194444,0.625000,0.050847,0.083333,0.066987,0.250000
0.055556,0.125000,0.050847,0.083333,0.066987,0.250000
0.027778,0.500000,0.050847,0.041667,0.066987,0.250000
0.194444,0.625000,0.101695,0.208333,0.066987,0.250000
0.222222,0.750000,0.152542,0.125000,0.066987,0.250000
0.138889,0.416667,0.067797,0.083333,0.066987,0.250000
0.222222,0.750000,0.101695,0.041667,0.066987,0.250000
0.083333,0.500000,0.067797,0.041667,0.066987,0.250000
0.277778,0.708333,0.084746,0.041667,0.066987,0.250000
0.194444,0.541667,0.067797,0.041667,0.066987,0.250000
0.750000,0.500000,0.627119,0.541667,1.000000,0.250000
0.583333,0.500000,0.593220,0.583333,1.000000,0.250000
0.722222,0.458333,0.661017,0.583333,1.000000,0.250000
0.333333,0.125000,0.508475,0.500000,1.000000,0.250000
0.611111,0.333333,0.610169,0.583333,1.000000,0.250000
0.388889,0.333333,0.593220,0.500000,1.000000,0.250000
0.555556,0.541667,0.627119,0.625000,1.000000,0.250000
0.166667,0.166667,0.389831,0.375000,1.000000,0.250000
0.638889,0.375000,0.610169,0.500000,1.000000,0.250000
0.250000,0.291667,0.491525,0.541667,1.000000,0.250000
0.194444,0.000000,0.423729,0.375000,1.000000,0.250000
0.444444,0.416667,0.542373,0.583333,1.000000,0.250000
0.472222,0.083333,0.508475,0.375000,1.000000,0.250000
0.500000,0.375000,0.627119,0.541667,1.000000,0.250000
0.361111,0.375000,0.440678,0.500000,1.000000,0.250000
0.666667,0.458333,0.576271,0.541667,1.000000,0.250000
0.361111,0.416667,0.593220,0.583333,1.000000,0.250000
0.416667,0.291667,0.525424,0.375000,1.000000,0.250000
0.527778,0.083333,0.593220,0.583333,1.000000,0.250000
0.361111,0.208333,0.491525,0.416667,1.000000,0.250000
0.444444,0.500000,0.644068,0.708333,1.000000,0.250000
0.500000,0.333333,0.508475,0.500000,1.000000,0.250000
0.555556,0.208333,0.661017,0.583333,1.000000,0.250000
0.500000,0.333333,0.627119,0.458333,1.000000,0.250000
0.583333,0.375000,0.559322,0.500000,1.000000,0.250000
0.638889,0.416667,0.576271,0.541667,1.000000,0.250000
0.694444,0.333333,0.644068,0.541667,1.000000,0.250000
0.666667,0.416667,0.677966,0.666667,1.000000,0.250000
0.472222,0.375000,0.593220,0.583333,1.000000,0.250000
0.388889,0.250000,0.423729,0.375000,1.000000,0.250000
0.333333,0.166667,0.474576,0.416667,1.000000,0.250000
0.333333,0.166667,0.457627,0.375000,1.000000,0.250000
0.416667,0.291667,0.491525,0.458333,1.000000,0.250000
0.472222,0.291667,0.694915,0.625000,1.000000,0.250000
0.305556,0.416667,0.593220,0.583333,1.000000,0.250000
0.472222,0.583333,0.593220,0.625000,1.000000,0.250000
0.666667,0.458333,0.627119,0.583333,1.000000,0.250000
0.555556,0.125000,0.576271,0.500000,1.000000,0.250000
0.361111,0.416667,0.525424,0.500000,1.000000,0.250000
0.333333,0.208333,0.508475,0.500000,1.000000,0.250000
0.333333,0.250000,0.576271,0.458333,1.000000,0.250000
0.500000,0.416667,0.610169,0.541667,1.000000,0.250000
0.416667,0.250000,0.508475,0.458333,1.000000,0.250000
0.194444,0.125000,0.389831,0.375000,1.000000,0.250000
0.361111,0.291667,0.542373,0.500000,1.000000,0.250000
0.388889,0.416667,0.542373,0.458333,1.000000,0.250000
0.388889,0.375000,0.542373,0.500000,1.000000,0.250000
0.527778,0.375000,0.559322,0.500000,1.000000,0.250000
0.222222,0.208333,0.338983,0.416667,1.000000,0.250000
0.388889,0.333333,0.525424,0.500000,1.000000,0.250000
0.555556,0.541667,0.847458,1.000000,0.500000,1.000000
0.416667,0.291667,0.694915,0.750000,0.500000,1.000000
0.777778,0.416667,0.830508,0.833333,0.500000,1.000000
0.555556,0.375000,0.779661,0.708333,0.500000,1.000000
0.611111,0.416667,0.813559,0.875000,0.500000,1.000000
0.916667,0.416667,0.949153,0.833333,0.500000,1.000000
0.166667,0.208333,0.593220,0.666667,0.500000,1.000000
0.833333,0.375000,0.898305,0.708333,0.500000,1.000000
0.666667,0.208333,0.813559,0.708333,0.500000,1.000000
0.805556,0.666667,0.864407,1.000000,0.500000,1.000000
0.611111,0.500000,0.694915,0.791667,0.500000,1.000000
0.583333,0.291667,0.728814,0.750000,0.500000,1.000000
0.694444,0.416667,0.762712,0.833333,0.500000,1.000000
0.388889,0.208333,0.677966,0.791667,0.500000,1.000000
0.416667,0.333333,0.694915,0.958333,0.500000,1.000000
0.583333,0.500000,0.728814,0.916667,0.500000,1.000000
0.611111,0.416667,0.762712,0.708333,0.500000,1.000000
0.944444,0.750000,0.966102,0.875000,0.500000,1.000000
0.944444,0.250000,1.000000,0.916667,0.500000,1.000000
0.472222,0.083333,0.677966,0.583333,0.500000,1.000000
0.722222,0.500000,0.796610,0.916667,0.500000,1.000000
0.361111,0.333333,0.661017,0.791667,0.500000,1.000000
0.944444,0.333333,0.966102,0.791667,0.500000,1.000000
0.555556,0.291667,0.661017,0.708333,0.500000,1.000000
0.666667,0.541667,0.796610,0.833333,0.500000,1.000000
0.805556,0.500000,0.847458,0.708333,0.500000,1.000000
0.527778,0.333333,0.644068,0.708333,0.500000,1.000000
0.500000,0.416667,0.661017,0.708333,0.500000,1.000000
0.583333,0.333333,0.779661,0.833333,0.500000,1.000000
0.805556,0.416667,0.813559,0.625000,0.500000,1.000000
0.861111,0.333333,0.864407,0.750000,0.500000,1.000000
1.000000,0.750000,0.915254,0.791667,0.500000,1.000000
0.583333,0.333333,0.779661,0.875000,0.500000,1.000000
0.555556,0.333333,0.694915,0.583333,0.500000,1.000000
0.500000,0.250000,0.779661,0.541667,0.500000,1.000000
0.944444,0.416667,0.864407,0.916667,0.500000,1.000000
0.555556,0.583333,0.779661,0.958333,0.500000,1.000000
0.583333,0.458333,0.762712,0.708333,0.500000,1.000000
0.472222,0.416667,0.644068,0.708333,0.500000,1.000000
0.722222,0.458333,0.745763,0.833333,0.500000,1.000000
0.666667,0.458333,0.779661,0.958333,0.500000,1.000000
0.722222,0.458333,0.694915,0.916667,0.500000,1.000000
0.416667,0.291667,0.694915,0.750000,0.500000,1.000000
0.694444,0.500000,0.830508,0.916667,0.500000,1.000000
0.666667,0.541667,0.796610,1.000000,0.500000,1.000000
0.666667,0.416667,0.711864,0.916667,0.500000,1.000000
0.555556,0.208333,0.677966,0.750000,0.500000,1.000000
0.611111,0.416667,0.711864,0.791667,0.500000,1.000000
0.527778,0.583333,0.745763,0.916667,0.500000,1.000000
0.444444,0.416667,0.694915,0.708333,0.500000,1.000000

*/
void ExampleNormalize(int argIndex, int argc, char **argv) {	
	char filename[FILENAME_MAX];
	NORM_DATA *norm;
	DATA_SET *data;

	LocateFile("iris.csv",filename,FILENAME_MAX);
	norm = NormCreate();
	NormDefRange(norm,0,1);
	NormDefRange(norm,0,1);
	NormDefRange(norm,0,1);
	NormDefRange(norm,0,1);
	NormDefClass(norm,NORM_CLASS_EQUILATERAL,0,1);

	NormAnalyze(norm,filename);
	data = NormProcess(norm,filename,4,1);
	
	printf("Actual input count: %i\n", data->inputCount);
	printf("Actual output count: %i\n", data->idealCount);

	DataCSVSave(stdout,norm,data);
	NormDelete(norm);
}